package  
{
  import assets.Stage;
  import flash.display.DisplayObject;
  import flash.display.MovieClip;
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.net.SharedObject;
  import flash.utils.Dictionary;
  
	
	/**
   * ...
   * @author ivan
   */
  public class FuncyButtonTest extends Sprite 
  {    
    private const SAVED_SECTOR:String = "SAVED_SECTOR";
    
    public function FuncyButtonTest() 
    {
      
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      stage.stageFocusRect = false;
      
      super();
      
      var st:MovieClip = new Stage;      
      
      for (var i:int = 0; i < st.numChildren; i++)
      {
        var btn:FuncyButton = st.getChildAt(i) as FuncyButton;
        if (btn)
        {
          var shared:SharedObject = SharedObject.getLocal(SAVED_SECTOR);
          if (shared.data.unlock == null)
          {
            shared.data.unlock = new Dictionary();
          }
          btn.enabled = (shared.data.unlock[btn.sector]) || btn.sector == 67;
          
          trace("funcy button found");
          (btn as MovieClip).addEventListener(MouseEvent.CLICK, onClick);
        }
      }
      
      addChild(st);
    }
    
    private function onClick(e:Event):void
    {
      var b:FuncyButton = e.target as FuncyButton;
      trace("click on " + b.name);
      trace(b.sector);
      
      if (b.sector == 67)
      {
        // Sector 67 unlocks sector 1.
        var shared:SharedObject = SharedObject.getLocal(SAVED_SECTOR);
        shared.data.unlock[1] = true;
      }
    }
    
  }

}